package com.jic.market.impl.rest.allocation;

import com.jic.market.common.enums.PromotionAllocationStrategyEnum;
import com.jic.market.entity.AllocationModel;
import com.jic.market.request.after.TellAddAllocationRequest;
import com.jic.market.request.rest.allocation.CollectionThemeInfoRequest;
import com.jic.market.response.rest.allocation.QueryAllocationAndThemeInfoResponse;
import com.jic.market.service.AllocationService;
import com.jic.market.service.allocation.PromotionAddAllocationStrategy;
import com.jic.market.service.rest.allocation.QueryPromotionForAllocationStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author xuyongliang
 * @version V1.0
 * @className QueryPromotionForAllocationStrategyContext
 * @description TODO
 * @date 2020/4/10
 */
@Slf4j
@Component
public class QueryPromotionForAllocationStrategyContext {

    /**
     *使用线程安全的ConcurrentHashMap存储所有实现Strategy接口的Bean
     *key:beanName
     *value：实现Strategy接口Bean
     */
    private final Map<String, QueryPromotionForAllocationStrategy> strategyMap = new ConcurrentHashMap<>();

    @Autowired
    public QueryPromotionForAllocationStrategyContext(Map<String, QueryPromotionForAllocationStrategy> strategyMap) {
        this.strategyMap.clear();
        strategyMap.forEach((k, v)-> this.strategyMap.put(k, v));
    }

    /**
     * 添加活动信息
     * @param request
     * @return
     */
    public QueryAllocationAndThemeInfoResponse collectionThemeInfo(CollectionThemeInfoRequest request) {
        log.info("--------进入活动信息策略上下文request--{}-----",request);
        String value = QueryPromotionForAllocationEnum.getValue(request.getPromType());
        QueryAllocationAndThemeInfoResponse infoResp =
                strategyMap.get(value).collectionThemeInfo(request);

        return infoResp;
    }

}
